package com.redis.springtest;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;

import java.util.List;

public class PipeLineTest {
    public static void main(String[] args) {
        JedisPool pool = new JedisPool("10.2.37.41", 6379);
        Jedis jedis = pool.getResource();
        long start = System.currentTimeMillis();
        // 开启流水线
        Pipeline pipeline = jedis.pipelined();
        // 测试10万条数据读/写两个操作
        for (int i = 0; i < 100000; i++) {
            int j = i + 1;
            pipeline.set("pipeline_key_" + j, "pipeline_value_" + j);
            pipeline.get("pipeline_key_" + j);
        }

        // 同步执行不返回结果
        // pipeline.sync();
        // 返回执行命令的结果List
        List<Object> result = pipeline.syncAndReturnAll();
        long end = System.currentTimeMillis();
        // 计算耗时
        System.out.println("耗时:" + (end - start) + "毫秒");
    }
}
